package hot100;

public class Solution415 {

    public String addStrings(String num1, String num2) {
        StringBuilder ans = new StringBuilder();
        int index = Math.max(num1.length() - 1, num2.length() - 1);
        int forward = 0;
        while (index >= 0) {
            int n1 = index >= num1.length() ? 0 : num1.charAt(index) - '0';
            int n2 = index >= num2.length() ? 0 : num2.charAt(index) - '0';
            int res = n1 + n2 + forward;
            ans.append(res % 10);
            forward = res / 10;
            index--;
        }
        if (forward > 0) {
            ans.append(forward);
        }
        return ans.reverse().toString();
    }
}
